package org.liuyunfeng.web;

import feign.Request;
import org.liuyunfeng.clients.NameFeign;
import org.liuyunfeng.clients.UrlFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

/**
 * @author: TanJingyu
 * @create: 2022-09-06 16:16
 **/
@RestController
@RequestMapping("/hello")
public class HelloController {
    @Autowired
    private UrlFeign urlFeign;
    @Autowired
    private NameFeign nameFeign;

    @RequestMapping
    public Object hello(HttpServletRequest request, @RequestBody Node node) throws InterruptedException {
            TimeUnit.SECONDS.sleep(600);
        return "hello...world";
    }

    @GetMapping("/urlFeign")
    public Object urlFeign() {
        Request.Options options = new Request.Options(20000, 20000);
        Node node = new Node();
        node.setAge(20);
        node.setName("王吉");
        return urlFeign.hello(options, node);
    }

    @GetMapping("/nameFeign")
    public Object nameFeign() {
        Request.Options options = new Request.Options(60, TimeUnit.MINUTES, 60, TimeUnit.MINUTES, true);
        return nameFeign.hello(options);
    }


    public static class Node {
        private String name;
        private Integer age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }
    }
}

    